package com.javaclimb.music.controller;

import com.alibaba.fastjson.JSONObject;
import com.javaclimb.music.po.Admin;
import com.javaclimb.music.service.AdminService;
import com.javaclimb.music.utils.Consts;
import org.apache.tomcat.util.bcel.Const;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AdminController {
    @Autowired
    private AdminService adminService;

    @RequestMapping(value = "/admin/login/status",method = RequestMethod.POST)
    public Object loginStatus(Admin admin){
        JSONObject jsonObject = new JSONObject();
        String name = admin.getName();
        String password = admin.getPassword();
        int flag= adminService.getAdminByIdByPass(admin);
        if (flag != 0){
            jsonObject.put(Consts.CODE,1);
            jsonObject.put(Consts.MSG,"登陆成功");
            return jsonObject;
        }
        jsonObject.put(Consts.MSG,0);
        jsonObject.put(Consts.CODE,"用户名或密码错误");
        return jsonObject;
    }

    @RequestMapping(value = "/admin/save",method = RequestMethod.POST)
    public Object saveAdmin(Admin admin){
        JSONObject jsonObject = new JSONObject();
        int flag= adminService.saveAdmin(admin);
        if (flag != 0){
            jsonObject.put(Consts.CODE,1);
            jsonObject.put(Consts.MSG,"添加成功");
            return jsonObject;
        }
        jsonObject.put(Consts.MSG,0);
        jsonObject.put(Consts.CODE,"添加失败");
        return jsonObject;
    }
}
